-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fulfill or betray promises #68
base: master
Are you sure you want to change the base?
Conversation
Travis fails on this PR only for node 0.10 (#145.2). The 2 tests that fail are each other's mirror, for
I don't understand why. In all branches, it seems that the done() callback is called, or an assert fails. This is confirmed by the fact that tests on all other versions of node work. Does anybody have any ideas about what is happening? |
…hat should pass - added an actual to error reporting
Promise definition copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/es6-shim/index.d.ts
…stack trace for fulfill and betray
…hen there is no condition nop is not needed
…sted against either)
…iling - changed implementation of betray to avoid exception cycle, and added actual to assert error
the reason was a badly placed (pair of) braces
promise now returns the promise, if it is one
f4b2d64
to
0117313
Compare
Wow, thank you for doing that much work! I must've entirely forgotten about this and was notified by GitHub mentioning you added v8 to |
the reason for the failure is that the actual error message we expect is tested this contains a stringified version of this.actual (NOT opts.actual) - see Must.prototype.assert, `var msg = stringify(this.actual) + …` in this case, the actual is a Promise in the node 0.10 version, and only there, this is an object with strange properties `"_40", "_65", "_55", "_72"`, while in other versions of Node this is just an object with then and catch methods these properties are probably private Promise administration, that is exposed the existing Promise tests don't reveal this, because the only place where a Promise is stringified as actual in an assert call in the tests, is in the test for 'must.NOT.be.a.promise()', and there a crafted object is used, not a 'real' Promise the heart of the matter is thus the stringification of a Promise, which is nonsensical in all Node versions ('{}'), does not take into account the Node 0.10 weirdness, and is not really tested with the existing tests fixing this would require a change in Must.prototype.assert, which is a different issue
…calling stringify in test, and compare literally a better representation of this.actual in Must.prototype.assert would be a better solution, but is independent of this
I recently switched to must from chai, because I started to used Standardjs.
I do find the reasons why you created must meaningful ("Beware of libraries that assert
on property access", "RFC 2119", …), and find myself happier with must than chai.
In both cases, I am frustrated with testing Promises.
The current
must.resolve
andmust.reject
primitives lead me to complex codingstructures, embedded in Promise.all([]) constructs far to often (the same applies to chai
and its extensions).
This is an example of a Mocha test:
Note that the
initialised.must.reject
phrase doesn't work. There is no simple way toexpress that an AssertionError should be thrown when the promise resolves, without
doing something with this (
initialised.must.reject.to…
). To work, we would needsomething of the form
initialised.must.reject()
, i.e., a method call.If I want to say more about the returned value or error, and about the state of other
things after the promise settles, I seem to be forced to use complex Promise.all([])
constructs, and variables to store intermediate results.
In this PR, I offer an alternative that seems to work in my tests. We express that
a Promise must 'fulfill' or 'betrays' its intentions. The check fails if the Promise
does not settle in the way it must. If it does, the conditions that we express in
the 'fullfil' or 'betray' argument are tested.
The whole can be returned in a test, which is the most pleasing way most test frameworks
support asynchronous tests.
With these new methods, the above test now becomes:
There is much less accidental complexity in this form.
More examples are in the JS Doc.
I you find to time, it would be nice if you could review this solution, and give me
any feedback that you deem relevant.